home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
gamesrc
/
rtanksrc
/
host.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-07
|
13KB
|
543 lines
void sort_results(void);
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include "dtypes.h"
#include <alloc.h>
#include "keybd.h"
#include <conio.h>
#include <bios.h>
#include <string.h>
#include "host.h"
#include "loadpcx.h"
#include "ginput.h"
#include "newload.h"
#include "callasm.h"
#include "newterp.h"
#include "bullet.h"
#include "bullet.ext"
#include "tiles.h"
#include "code.h"
#include "tss.h"
void view_manual(void);
void init_manual_track();
void inc_manual_track();
#define SCORE struct score_type
SCORE {
int seconds;
int player;
int hits;
};
SCORE res[11];
int chassis = 1;
int weapons[] = {0,0,0,0,0,0,0,0,0,0,0,0};
int extras[] = {0,0,0,0,0,0,0,0,0,0,0,0};
int px[] = {40,40,40,25,25,25,175,175,175,100};
int py[] = {48,72,96,126,141,156,126,141,156,171};
TSS tnk;
PSTR wind;
BOOL fileerr = FALSE;
int num_players;
int terrain;
PLAYER players[10];
p_TANK point[10];
BOOL update_scr;
BOOL cwe=TRUE; /* Compiled with Errors */
int x,y;
/*-------------------------------------
* Function : void load_battle_specs(void)
* Purpose : Load in all info required for battle from BATTLE.DAT
* Date : 02/26/1989 18:01:01
*/
void load_battle_specs(void)
{
FILE *fp;
int a,b, hand;
TSS pl;
p_TANK tp;
char buf[20];
x=5; y=3;
/*
printf("Available ram DS = %u HEAP = %lu\n",coreleft(),(long) farcoreleft());
*/
if ((fp=fopen("BATTLE.DAT","rb"))==NULL) {
printf("Cannot open BATTLE.DAT for input\n");
printf("Run program from NEWSHOP.EXE \n");
exit(1);
}
num_players=getw(fp);
terrain =getw(fp)+1;
for (a=0; a<10; a++) {
players[a].inbattle=FALSE;
players[a].active=FALSE;
point[a]=NULL;
}
/*
printf("%d contestants, terrain %d\n",num_players,terrain);
*/
for (a=0; a<num_players; a++) {
fread(&pl,sizeof(TSS),1,fp);
/*
printf("%d. %s team %d\n",a+1,pl.name, pl.team);
*/
strcpy(players[a].tankname, pl.name);
players[a].chassisType = pl.t_chassis;
players[a].inbattle=TRUE;
players[a].active=TRUE;
for (b=0; b<10; b++) {
players[a].weaponsType[b]=pl.t_weapons[b];
players[a].extrasType[b]=pl.t_extras[b];
}
setcolor(BLACK);
sprintf(buf,"Compiling \"%s\"",pl.name);
note_error(buf);
setcolor(CGA_WHITE);
hand= n_compile_player(&players[a]);
if (hand<0)
cwe=TRUE;
players[a].tank_handle=hand;
tp=get_tank_pointer(players[a].tank_handle);
init_tank_image(tp,pl.team);
players[a].dteam=pl.team;
}
fclose(fp);
} /* void load_battle_specs(void) */
/*-------------------------------------
* Function : void main(void)
* Purpose : Main calling module for HOST.C
* Date : 02/19/1989 17:10:26
*/
void main(void)
{
num_players=0;
cwe=FALSE;
register_bgi();
set_screen_mode(4);
Load_CGA_PCX("Z4400.B31");
load_battle_specs();
if (!cwe) {
show_error("TO START BATTLE,");
host_battle();
} else
getchar();
closegraph();
}
/*-------------------------------------
* Function : void register_bgi(void)
* Purpose : Register the BGI driver for CGA
* Date : 02/19/1989 17:16:18
*/
void register_bgi(void)
{
int gm, gd;
if (registerfarbgidriver(CGA_driver_far) < 0) {
printf("Color graphics adapter required for this program\n");
exit(1);
};
gm=CGAC1;
gd=CGA;
initgraph(&gd,&gm,"");
if (graphresult()<0) {
printf("Graphics driver initilization error, CGA required\n");
exit(1);
}
} /* void register_bgi(void) */
/*-------------------------------------
* Function : void open_wind(void)
* Purpose : Open dialog box window
* Date : 02/26/1989 12:53:21
*/
void open_wind(void)
{
int size;
size=imagesize(70,70,250,160);
if ((wind=malloc(size))==NULL) {
printf("Cannot Malloc()\n");
exit(1); /* Temp error */
}
getimage(70,70,250,160,wind);
setfillstyle(CLOSE_DOT_FILL,CGA_RED);
bar(70,70,250,160);
setfillstyle(SOLID_FILL,CGA_WHITE);
bar(80,80,240,150);
setcolor(BLACK);
rectangle(70,70,250,160);
rectangle(80,80,240,150);
} /* void open_wind(void) */
/*-------------------------------------
* Function : void close_wind(void)
* Purpose : Close dialog box window
* Date : 02/26/1989 12:57:05
*/
void close_wind(void)
{
putimage(70,70,wind,COPY_PUT);
free(wind);
} /* void close_wind(void) */
void show_error(char *s)
{
open_wind();
moveto(85,100);
outtext(s);
moveto(110,120);
outtext("PRESS ENTER ");
ggetline(1," ");
close_wind();
} /* void show_error(char *s) */
/*<f>----------------------------------------
* FUNCTION: <s> void host_battle(void)
* PURPOSE : Monitor keyboard and host the COMBAT!!!!
* :
* CREATION: 01/09/1989 11:44:56
*/
void host_battle(void)
{
p_TANK pl;
int a,c,ch,z, monvar;
BOOL cont;
BOOL manual;
randomize();
manual=FALSE;
init_bullets();
v_startup_playfield(terrain);
for (a=0; a<num_players; a++) {
point[a]=get_tank_pointer(players[a].tank_handle);
point[a]->time = biostime(0,0);
point[a]->died = point[a]->died;
init_interpreter(point[a]);
save_under_tank(point[a]);
point[a]->team=players[a].dteam;
point[a]->var[CMYTEAM]=point[a]->team;
}
a=0; cont=TRUE; monvar=0;
while (cont) {
c=0;
while (!players[a].inbattle && c<num_players) {
a++; if (a==num_players) a=0;
c++;
}
if (c==num_players)
cont=FALSE;
else {
pl=point[a];
set_move_range(pl);
gotoxy( 8,21); printf("%2d",a+1);
gotoxy(25,21); printf("%-8s",players[a].tankname);
gotoxy( 8,22); printf("%3d",pl->nhits);
gotoxy(1,23); printf("VAR[%02d]=%4d",monvar,pl->var[monvar]);
capturescr();
update_scr=TRUE;
while (!kbhit()) {
for (z=0; z<num_players; z++)
interprete(point[z],&players[z]);
move_bullets();
check_for_hits();
move_bullets();
check_for_hits();
if (update_scr) {
if (!manual)
monitor_tank(pl);
else
view_manual();
}
update_scr=FALSE;
}
if (!kbhit())
ch=' ';
else
ch=getkey();
switch (ch) {
case ' ': a++;
if (a>=num_players) a=0;
manual=FALSE;
break;
case 27 : cont=FALSE;
case '<':
case ',': monvar--; if (monvar<0) monvar=49;
break;
case '>':
case '.': monvar++; if (monvar>=50) monvar=0;
break;
case UP_ARR : if (!manual) {
manual=TRUE;
init_manual_track();
}
inc_manual_view(0,-1);
break;
case DN_ARR : if (!manual) {
manual=TRUE;
init_manual_track();
}
inc_manual_view(0,1);
break;
case LF_ARR : if (!manual) {
manual=TRUE;
init_manual_track();
}
inc_manual_view(-1,0);
break;
case RT_ARR : if (!manual) {
manual=TRUE;
init_manual_track();
}
inc_manual_view(1,0);
break;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': manual=FALSE;
a=ch-'1';
break;
case '0': manual=FALSE;
a=9;
break;
}
}
}
conclude_battle();
} /* void host_battle(void) */
/*<f>----------------------------------------
* FUNCTION: <s> void check_for_hits(void)
* PURPOSE : Check if any bullets hit a tank or not
* :
* CREATION: 01/10/1989 14:05:17
*/
void check_for_hits(void)
{
int a,b;
if (nhits==0) return;
for (b=0; b<nhits; b++)
for (a=0; a<num_players; a++)
if (players[a].active &&
(hits[b].hx==point[a]->px || hits[b].hx==point[a]->px+1) &&
(hits[b].hy==point[a]->py || hits[b].hy==point[a]->py+1)
) {
point[a]->boom=TRUE;
point[a]->bwait=10;
if ((point[a]->nhits++) > 28) {
players[a].active=FALSE;
setmapXY(point[a]->px ,point[a]->py ,DEAD1A);
setmapXY(point[a]->px+1,point[a]->py ,DEAD1B);
setmapXY(point[a]->px ,point[a]->py+1,DEAD1C);
setmapXY(point[a]->px+1,point[a]->py+1,DEAD1D);
point[a]->died=biostime(0,0);
}
point[a]->hit=TRUE;
}
} /* void check_for_hits(void) */
/*<f>----------------------------------------
* FUNCTION: <s> void conclude_battle(void)
* PURPOSE : List battle standings
* :
* CREATION: 01/11/1989 18:41:34
*/
void conclude_battle(void)
{
int a;
char steam[10];
char buf[80];
DWORD t;
t=biostime(0,0);
Load_CGA_PCX("YXZ23.CXA");
gotoxy(1,1);
for (a=0; a<num_players; a++) {
if (players[a].active)
point[a]->died=t;
point[a]->secs = (point[a]->died-point[a]->time) / 18;
if (point[a]->secs<0)
point[a]->secs = (65535+point[a]->died-point[a]->time) /18;
res[a].seconds = point[a]->secs;
res[a].player = a;
res[a].hits = point[a]->nhits;
}
sort_results();
for (a=0; a<num_players; a++) {
moveto(px[a],py[a]);
if (players[a].inbattle) {
if (players[res[a].player].active)
setcolor(BLACK);
else setcolor(CGA_RED);
switch(players[res[a].player].dteam) {
case ALLOUT : strcpy(steam,"N"); break;
case TEAMA : strcpy(steam,"A"); break;
case TEAMB : strcpy(steam,"B"); break;
}
if (a<3)
sprintf(buf,"%8s %3d %s %02d:%02d",
players[res[a].player].tankname,
point[res[a].player]->nhits,
steam,
res[a].seconds / 60,
res[a].seconds % 60
);
else
sprintf(buf,"%8s %s %02d:%02d",
players[res[a].player].tankname,
steam,
res[a].seconds / 60,
res[a].seconds % 60
);
outtext(buf);
}
}
while (!kbhit())
;
(void) getch();
} /* void conclude_battle(void) */
/*-------------------------------------
* Function : void note_error(char *s)
* Purpose : Display a line of graphical text
* Date : 02/26/1989 20:25:24
*/
void note_error(char *s)
{
outtextxy(x,(y++)*9,s);
if (y>21) {
moveto(300,185); ggetline(1," ");
setfillstyle(SOLID_FILL,CGA_RED);
bar(5,25,310,197);
y=3;
}
} /* void note_error(char *s) */
/*-------------------------------------
* Function : void sort_results(void)
* Purpose : Sort player results based on time in the ring
* Date : 03/01/1989 14:39:34
*/
void sort_results(void)
{
int a,b, limit;
SCORE t;
BOOL witch=TRUE;
limit=num_players;
while (witch && limit>0) {
witch=FALSE;
for (a=0; a<limit-1; a++) {
if (
(res[a].seconds < res[a+1].seconds) || /* shorter time */
(
(res[a].seconds == res[a+1].seconds) && /* fewer hits */
(res[a].hits > res[a+1].hits)
)
) {
t=res[a];
res[a]=res[a+1];
res[a+1]=t;
witch = a;
}
}
limit--;
}
} /* void sort_results(void) */